class Solution {
public:
    int longestSubsequence(vector<int>& a, int k) {
        unordered_map<int, int>mp;
        int n = a.size();
        int ma = 0;
        for (auto& x : a) {
            mp[x] = mp[x - k] + 1;
            ma = max(mp[x], ma);
        }
        return ma;
    }
};